package com.yoshino.principle.openclosed;


import lombok.extern.slf4j.Slf4j;

/**
 * @author yoshino
 **/
@Slf4j
public class Ocp {
    public static void main(String[] args) {
        // 使用查看存在的问题
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawShape(new Rectangle());
        graphicEditor.drawShape(new Circle());
        graphicEditor.drawShape(new Triangle());
    }
}

@Slf4j
class GraphicEditor {
    public void drawShape(Shape s) {
        s.draw();
    }
}

/**
 * Shape 类，记基类
 */
abstract class Shape {
    int mType;

    /**
     * 抽象方法
     */
    public abstract void draw();
}

@Slf4j
class Rectangle extends Shape {
    Rectangle() {
        super.mType = 1;
    }

    @Override
    public void draw() {
        log.info("绘制矩形");
    }
}

@Slf4j
class Circle extends Shape {
    Circle() {
        super.mType = 2;
    }

    @Override
    public void draw() {
        log.info("绘制圆形");
    }
}

/**
 * 新增画三角形：新增代码
 */
@Slf4j
class Triangle extends Shape {
    Triangle() {
        super.mType = 3;
    }

    @Override
    public void draw() {
        log.info("绘制三角形");
    }
}